package com.disability_federation.controller;

import com.disability_federation.mapper.MapperWorkingPersonnelList;
import com.disability_federation.pojo.WorkingPersonnelList;
import com.disability_federation.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * 残联工作员列表操作接口
 */
@RestController
@CrossOrigin
public class ControllerWorkingPersonnelList {

    @Autowired
    private MapperWorkingPersonnelList mapperWorkingPersonnelList;

    /**
     * 查询全部员工列表
     * 默认更新时间升序排序
     */
    @RequestMapping("WPL/query")
    public Result query(){
        return Result.success(mapperWorkingPersonnelList.query());
    }

    /**
     * 查询全部员工列表
     * 更新时间降序排序
     */
    @RequestMapping("WPL/query/time_desc")
    public Result queryDesc(){
        return Result.success(mapperWorkingPersonnelList.queryDesc());
    }

    /**
     * 查询全部员工列表
     * 姓名升序排序
     */
    @RequestMapping("WPL/query/name_asc")
    public Result queryNameAsc(){
        return Result.success(mapperWorkingPersonnelList.queryNameAsc());
    }

    /**
     * 查询全部员工列表
     * 姓名降序排序
     */
    @RequestMapping("WPL/query/name_desc")
    public Result queryNameDesc(){
        return Result.success(mapperWorkingPersonnelList.queryNameDesc());
    }

    /**
     * 查询全部员工列表
     * 单位升序排序
     */
    @RequestMapping("WPL/query/unit_asc")
    public Result queryUnitAsc(){
        return Result.success(mapperWorkingPersonnelList.queryUnitAsc());
    }

    /**
     * 查询全部员工列表
     * 单位降序排序
     */
    @RequestMapping("WPL/query/unit_desc")
    public Result queryUnitDesc(){
        return Result.success(mapperWorkingPersonnelList.queryUnitDesc());
    }

    /**
     * 查询全部员工列表
     * 注册时间升序排序
     */
    @RequestMapping("WPL/query/register_time_asc")
    public Result queryRegisterTimeAsc(){
        return Result.success(mapperWorkingPersonnelList.queryRegisterTimeAsc());
    }

    /**
     * 查询全部员工列表
     * 注册时间降序排序
     */
    @RequestMapping("WPL/query/register_time_desc")
    public Result queryRegisterTimeDesc(){
        return Result.success(mapperWorkingPersonnelList.queryRegisterTimeDesc());
    }

    /**
     * 条件查询员工列表
     * 默认更新时间升序排序
     */
    @RequestMapping("WPL/query/condition")
    public Result queryCondition(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryCondition(name, unit, gender));
    }

    /**
     * 条件查询员工列表
     * 更新时间降序排序
     */
    @RequestMapping("WPL/query/condition/time_desc")
    public Result queryConditionDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryConditionDesc(name, unit, gender));
    }

    /**
     * 条件查询员工列表
     * 姓名升序排序
     */
    @RequestMapping("WPL/query/condition/name_asc")
    public Result queryConditionNameAsc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryConditionNameAsc(name, unit, gender));
    }

    /**
     * 条件查询员工列表
     * 姓名降序排序
     */
    @RequestMapping("WPL/query/condition/name_desc")
    public Result queryConditionNameDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryConditionNameDesc(name, unit, gender));
    }

    /**
     * 条件查询员工列表
     * 单位升序排序
     */
    @RequestMapping("WPL/query/condition/unit_asc")
    public Result queryConditionUnitAsc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryConditionUnitAsc(name, unit, gender));
    }

    /**
     * 条件查询员工列表
     * 单位降序排序
     */
    @RequestMapping("WPL/query/condition/unit_desc")
    public Result queryConditionUnitDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryConditionUnitDesc(name, unit, gender));
    }

    /**
     * 条件查询员工列表
     * 注册时间升序排序
     */
    @RequestMapping("WPL/query/condition/register_time_asc")
    public Result queryConditionRegisterTimeAsc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryConditionRegisterTimeAsc(name, unit, gender));
    }

    /**
     * 条件查询员工列表
     * 注册时间降序排序
     */
    @RequestMapping("WPL/query/condition/register_time_desc")
    public Result queryConditionRegisterTimeDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryConditionRegisterTimeDesc(name, unit, gender));
    }

    /**
     * 增加员工
     */
    @RequestMapping("WPL/management/add")
    public Result add(@RequestParam String username, String name, Integer gender, LocalDate birthday, String phone, String email, String password){
        WorkingPersonnelList workingPersonnelList = new WorkingPersonnelList();
        workingPersonnelList.setUsername(username);
        workingPersonnelList.setName(name);
        workingPersonnelList.setGender(gender);
        workingPersonnelList.setBirthday(birthday);
        workingPersonnelList.setPhone(phone);
        workingPersonnelList.setEmail(email);
        workingPersonnelList.setPassword(password);
        if(mapperWorkingPersonnelList.add(workingPersonnelList)>0){
            return Result.success(null);
        }else{
            return Result.fail();
        }
    }

    /**
     * 删除员工
     */
    @RequestMapping("WPL/management/delete")
    public Result delete(@RequestParam Integer id){
        if(mapperWorkingPersonnelList.delete(id)>0){
            return Result.success(null);
        }else{
            return Result.fail();
        }
    }

    /**
     * 批量删除员工
     */
    @RequestMapping("WPL/management/deleteBatch")
    public Result deleteBatch(@RequestParam Integer[] ids){
        if(mapperWorkingPersonnelList.deleteBatch(ids)>0){
            return Result.success(null);
        }else{
            return Result.fail();
        }
    }

    /**
     * 更新员工信息
     */
    @RequestMapping("WPL/management/update")
    public Result update(@RequestBody WorkingPersonnelList workingPersonnelList){
        if(mapperWorkingPersonnelList.update(workingPersonnelList)>0){
            return Result.success(null);
        }else{
            return Result.fail();
        }
    }

    /**
     * 查询全部残疾员工
     * 默认更新时间升序排序
     */
    @RequestMapping("WPL/disable/query")
    public Result queryDisable(){
        return Result.success(mapperWorkingPersonnelList.queryDisable());
    }

    /**
     * 查询全部残疾员工
     * 更新时间降序排序
     */
    @RequestMapping("WPL/disable/query/time_desc")
    public Result queryDisableDesc(){
        return Result.success(mapperWorkingPersonnelList.queryDisableDesc());
    }

    /**
     * 查询全部残疾员工
     * 姓名升序排序
     */
    @RequestMapping("WPL/disable/query/name_asc")
    public Result queryDisableNameAsc(){
        return Result.success(mapperWorkingPersonnelList.queryDisableNameAsc());
    }

    /**
     * 查询全部残疾员工
     * 姓名降序排序
     */
    @RequestMapping("WPL/disable/query/name_desc")
    public Result queryDisableNameDesc(){
        return Result.success(mapperWorkingPersonnelList.queryDisableNameDesc());
    }

    /**
     * 查询全部残疾员工
     * 注册时间升序排序
     */
    @RequestMapping("WPL/disable/query/register_time_asc")
    public Result queryDisableRegisterTimeAsc(){
        return Result.success(mapperWorkingPersonnelList.queryDisableRegisterTimeAsc());
    }

    /**
     * 查询全部残疾员工
     * 注册时间降序排序
     */
    @RequestMapping("WPL/disable/query/register_time_desc")
    public Result queryDisableRegisterTimeDesc(){
        return Result.success(mapperWorkingPersonnelList.queryDisableRegisterTimeDesc());
    }

    /**
     * 查询全部残疾员工
     * 单位升序排序
     */
    @RequestMapping("WPL/disable/query/unit_asc")
    public Result queryDisableUnitAsc(){
        return Result.success(mapperWorkingPersonnelList.queryDisableUnitAsc());
    }

    /**
     * 查询全部残疾员工
     * 单位降序排序
     */
    @RequestMapping("WPL/disable/query/unit_desc")
    public Result queryDisableUnitDesc(){
        return Result.success(mapperWorkingPersonnelList.queryDisableUnitDesc());
    }

    /**
     * 条件查询残疾员工
     * 默认更新时间升序排序
     */
    @RequestMapping("WPL/disable/query/condition")
    public Result queryDisableCondition(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableCondition(name, unit, gender));
    }

    /**
     * 条件查询残疾员工
     * 更新时间降序排序
     */
    @RequestMapping("WPL/disable/query/condition/time_desc")
    public Result queryDisableConditionDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableConditionDesc(name, unit, gender));
    }

    /**
     * 条件查询残疾员工
     * 姓名升序排序
     */
    @RequestMapping("WPL/disable/query/condition/name_asc")
    public Result queryDisableConditionNameAsc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableConditionNameAsc(name, unit, gender));
    }

    /**
     * 条件查询残疾员工
     * 姓名降序排序
     */
    @RequestMapping("WPL/disable/query/condition/name_desc")
    public Result queryDisableConditionNameDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableConditionNameDesc(name, unit, gender));
    }

    /**
     * 条件查询残疾员工
     * 注册时间升序排序
     */
    @RequestMapping("WPL/disable/query/condition/register_time_asc")
    public Result queryDisableConditionRegisterTimeAsc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableConditionRegisterTimeAsc(name, unit, gender));
    }

    /**
     * 条件查询残疾员工
     * 注册时间降序排序
     */
    @RequestMapping("WPL/disable/query/condition/register_time_desc")
    public Result queryDisableConditionRegisterTimeDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableConditionRegisterTimeDesc(name, unit, gender));
    }

    /**
     * 条件查询残疾员工
     * 单位升序排序
     */
    @RequestMapping("WPL/disable/query/condition/unit_asc")
    public Result queryDisableConditionUnitAsc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableConditionUnitAsc(name, unit, gender));
    }

    /**
     * 条件查询残疾员工
     * 单位降序排序
     */
    @RequestMapping("WPL/disable/query/condition/unit_desc")
    public Result queryDisableConditionUnitDesc(String name, String unit, Integer gender){
        return Result.success(mapperWorkingPersonnelList.queryDisableConditionUnitDesc(name, unit, gender));
    }

}
